﻿using System.Windows.Controls;

namespace content.A04
{
    public partial class A0402:Page
    {
        public A0402()
        {
            InitializeComponent();

            Loaded+=delegate
            {
                ListBox1.Items.Add($"{"课程名",-10}{"开设学期",-10}{"书名",-20}{"定价",5}");
                ListBox1.Items.Add((new CourseInfo {CourseName="数据结构",CourseSemester=CourseTime.秋季,BookName="《数据结构》",Price=40}).Print());
                ListBox1.Items.Add((new CourseInfo {CourseName="操作系统",CourseSemester=CourseTime.秋季,BookName="《操作系统》",Price=45}).Print());
                ListBox1.Items.Add((new CourseInfo {CourseName="软件工程",CourseSemester=CourseTime.秋季,BookName="《软件工程》",Price=38}).Print());
            };
        }

        enum CourseTime
        {
            春季,
            秋季
        }

        private class CourseInfo
        {
            public string CourseName{get;set;}
            public CourseTime CourseSemester;
            public string BookName{get;set;}
            public double Price{get;set;}

            private static int _counter=0;

            public CourseInfo()
            {
                _counter++;
                CourseName=BookName="<null>";
                CourseSemester=CourseTime.春季;
                Price=0;
            }

            public CourseInfo(string courseName,string bookName,CourseTime courseSemester,int price)
            {
                _counter++;
                CourseName=courseName;
                BookName=bookName;
                CourseSemester=courseSemester;
                Price=price;
            }

            public string Print()
            {
                return$"{CourseName,-10}{CourseSemester,-10}{BookName,-10}{Price,10}";
            }
        }
    }
}